// index.js
Page({
  data: {
    imageArr: [{}],
    listArr: [{}],
    MenuArr: [{}],
    pageNum: 1
  },
  onLoad(options) {
    this.LoadImgList()
    this.LoadProList()
    this.LoadMenu()
  },
  LoadImgList() {
    wx.request({
      url: 'http://47.94.6.186:3001/api/banner/list',
      method: 'GET',
      success: res => {
        this.setData({
          imageArr: res.data.data
        })
      },
    })
  },
  LoadProList(callback) {
    wx.request({
      url: 'http://47.94.6.186:3001/api/pro/list',
      method: 'GET',
      data: {
        count: this.data.pageNum,
        limitNum: 10,
      },
      success: res => {
        this.setData({
          listArr: [...this.data.listArr, ...res.data.data]
        })
        if (callback) {
          callback()
        }
      },
    })
  },
  LoadMenu() {
    wx.request({
      url: 'http://47.94.6.186:3001/api/menu/list',
      method: 'GET',
      success: res => {
        this.setData({
          MenuArr: res.data.data
        })
      },
    })
  },
  onReachBottom() {
    this.data.pageNum++
    this.LoadProList()
  },
  onPullDownRefresh() {
    this.data.listArr = []
    this.data.pageNum = 1
    this.LoadProList(function () {
      console.log("结束了刷新");
      wx.stopPullDownRefresh()
    })
  }
})
